package com.ucl.model.entity.system;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.ucl.common.validator.Create;
import com.ucl.common.validator.FieldRepeatValidator;
import com.ucl.common.validator.Update;
import com.ucl.model.entity.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

@Data
@ApiModel(description = "系统管理-用户基础信息表")
@TableName("t_sys_user")
@FieldRepeatValidator(field = "username", message = "账号重复，请重新输入账号！")
public class SysUser extends BaseEntity<SysUser> {

    private static final long serialVersionUID = -5211183728776997271L;

    /**
     * 主键ID  groups:标识在更新的时候才能验证非空
     */
    @ApiModelProperty(value = "主键ID")
    @TableId(value="id", type= IdType.AUTO)
    @NotNull(message = "用户id不能为空", groups={Update.class})
    private Integer id;

    @ApiModelProperty(value = "账号")
    @TableField("username")
    @NotBlank(message = "账号不能为空", groups = {Create.class, Update.class})
    @Length(max = 100, message = "账号不能超过100个字符")
    @Pattern(regexp = "^[\\u4E00-\\u9FA5A-Za-z0-9\\*]*$", message = "账号限制：最多100字符，包含文字、字母和数字")
    private String username;

    @ApiModelProperty(value = "登录密码")
    @TableField("password")
    private String password;

    @ApiModelProperty(value = "昵称")
    @TableField("nick_name")
    @NotBlank(message = "昵称不能为空")
    private String nickName;

    @ApiModelProperty(value = "性别 0:男 1:女")
    @TableField("sex")
    private Boolean sex;

    @ApiModelProperty(value = "手机号码")
    @TableField("phone")
    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误")
    private String phone;

    @ApiModelProperty(value = "邮箱")
    @TableField("email")
    @NotBlank(message = "联系邮箱不能为空")
    @Email(message = "邮箱格式不对")
    private String email;

    @ApiModelProperty(value = "头像")
    @TableField("avatar")
    private String avatar;

    @ApiModelProperty(value = "状态 0:无效 1:有效")
    @TableField("status")
    private Boolean status;

    @ApiModelProperty(value = "盐值")
    @TableField("salt")
    private String salt;

    @ApiModelProperty(value = "token")
    @TableField("token")
    private String token;

    @ApiModelProperty(value = "明文密码")
    @TableField("pwd")
    @NotBlank(message = "密码不能为空")
    private String pwd;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}